//用户修改搜索框失去焦点保存val值
$("#search").blur(function(){
    console.log($(this).val());
})
// 行政区
$(".area").click(function(){
    $(".hotel_area").toggle();
    $(".area").toggleClass("checkedColor");
    $(".area i").toggleClass("checkedI");
    var cityName=$("#selectCity").val();
    $.ajax({
        url:url+"v1/city/area",
        // url:"php/xingzhengqu.js",
        method:"GET",
        dataType:"json",
        data:{
            cityName:cityName
        },
        xhrFields:{
            withCredentials:true
        }
    })
    .done(function(data){
        // console.log(data);
        if(data.code=="success"){
            $(".hotel_area").find("ul").remove();
            var str='<ul class="clearfix">';
                for(i=0;i<data.data.area.length;i++){
                    str+='<li title="'+data.data.area[i]+'">'+data.data.area[i]+'</li>';
                }
            str+='</ul>';
            $(".hotel_area").append(str);
        }else if(data.code=="city_not_found"){
            $(".hotel_area").find("ul").remove();
            $(".area .notFound_position").css("display","block");
        }
    })
    $(".ErrorMsg").css("display","none");
        
})
$(".hotel_area").on("click","li",function(){
    // console.log($(this).html());
    $("#search").val($(this).html());
})
// 商圈
$(".trad").click(function(){
    $(".hotel_trad").toggle();
    $(".trad").toggleClass("checkedColor");
    $(".trad i").toggleClass("checkedI");
    var cityName=$("#selectCity").val();
    $.ajax({
        url:url+"v1/city/trad",
        // url:"php/shangquan.js",
        method:"GET",
        dataType:"json",
        data:{
            cityName:cityName
        },
        xhrFields:{
            withCredentials:true
        }
    })
    .done(function(data){
        // console.log(data);
        if(data.code=="success"){
            $(".hotel_trad").find("ul").remove();
            var str='<ul class="clearfix">';
                for(i=0;i<data.data.trad.length;i++){
                    str+='<li title="'+data.data.trad[i]+'">'+data.data.trad[i]+'</li>';
                }
            str+='</ul>';
            $(".hotel_trad").append(str);
        }else if(data.code=="city_not_found"){
            $(".hotel_trad").find("ul").remove();
            $(".trad .notFound_position").css("display","block");
        }
    })
    $(".ErrorMsg").css("display","none");
})
$(".hotel_trad").on("click","li",function(){
    // console.log($(this).html());
    $("#search").val($(this).html());
})
// 地铁
$(".subway").click(function(){
    $(".hotel_subway").toggle();
    $(".subway").toggleClass("checkedColor");
    $(".subway i").toggleClass("checkedI");
    var cityName=$("#selectCity").val();
    $.ajax({
        url:url+"v1/city/subway/station",
        // url:"php/ditie.js",
        method:"GET",
        dataType:"json",
        data:{
            cityName:cityName
        },
        xhrFields:{
            withCredentials:true
        }
    })
    .done(function(data){
        if(data.code=="success"){
            $(".Metro_Line").find("li").remove();
            var subway=data.data.subway;
            var subwayLine="";
            // console.log(subway["地铁1号线"]);            
            var a=[];
            for(var i in subway){
                console.log(i);
                a.push(i);
            }
            for(j=0;j<a.length;j++){
                subwayLine+='<li class="subwayTitle">'+a[j]+'</li>';
            }
            $(".Metro_Line").append(subwayLine);

            
            $(".Metro_Line li").on('mouseover',function(){
                $(this).css({'background':'#5944C3','color':'#fff'}).siblings().css({'background':'#fff','color':'#3E3E3E'});
                var subwayLine=$(this).html();
                console.log(subway[subwayLine]);
                var abc="";
                for(i=0;i<subway[subwayLine].length;i++){
                    abc+='<li>'+subway[subwayLine][i]+'</li>';
                }
                $(".one_line li").remove();
                $(".one_line").append(abc);
            })
            
        }else if(data.code=="city_not_found"){
            $(".hotel_subway").find("ul").remove();
            $(".subway .notFound_position").css("display","block");
        }
    })
    $(".ErrorMsg").css("display","none");
})
$(".hotel_subway").on("click","li",function(){
    // console.log($(this).html());
    $("#search").val($(this).html());
})
// 车站
$(".station").click(function(){
    $(".hotel_station").toggle();
    $(".station").toggleClass("checkedColor");
    $(".station i").toggleClass("checkedI");
    var cityName=$("#selectCity").val();
    $.ajax({
        url:url+"v1/city/station",
        // url:"php/chezhan.js",
        method:"GET",
        dataType:"json",
        data:{
            cityName:cityName
        },
        xhrFields:{
            withCredentials:true
        }
    })
    .done(function(data){
        // console.log(data);
        if(data.code=="success"){
            $(".hotel_station ul").find("li").remove();
            var station_data=data.data.station;
            var train=station_data["火车站"];
            var train_str='';
            if(train.length<=0){
                train_str+='<li>暂无该城市数据</>';
                $(".hotel_station .train").append(train_str);
            }else{
                train_str+='<li><img src="img/icon_train.png"></li>';
                for(i=0;i<train.length;i++){
                    train_str+='<li title="'+train[i]+'">'+train[i]+'</li>';
                }
                $(".hotel_station .train").append(train_str);
            }
            
            var bus=data.data.station["长途汽车站"];
            var bus_str="";
            if(bus.length<=0){
                bus_str+='<li>暂无该城市数据</li>';
                $(".hotel_station .bus").append(bus_str);
            }else{
                bus_str+='<li><img src="img/icon_bus.png"></li>';
                for(i=0;i<bus.length;i++){
                    bus_str+='<li title="'+bus[i]+'">'+bus[i]+'</li>';
                }
                $(".hotel_station .bus").append(bus_str);
            }

            var airplane=data.data.station["飞机场"];
            var airplane_str="";
            if(airplane.length<=0){
                airplane_str+='<li>暂无该城市数据</li>';
                $(".hotel_station .airplane").append(airplane_str);
            }else{                
                airplane_str+='<li><img src="img/icon_airplane.png"></li>';
                for(i=0;i<airplane.length;i++){
                    airplane_str+='<li title="'+airplane[i]+'">'+airplane[i]+'</li>';
                }
                $(".hotel_station .airplane").append(airplane_str);
            }

            // $(".hotel_station").append(str);
        }else if(data.code=="city_not_found"){
            $(".hotel_station").find("ul").remove();
            $(".station .notFound_position").css("display","block");
        }
    })
    $(".ErrorMsg").css("display","none");
})
$(".hotel_station").on("click","li",function(){
    $("#search").val($(this).html());
})
// 景点
$(".spot").click(function(){
    $(".hotel_spot").toggle();
    $(".spot").toggleClass("checkedColor");
    $(".spot i").toggleClass("checkedI");
    var cityName=$("#selectCity").val();
    $.ajax({
        url:url+"v1/city/view/spot",
        // url:"php/jingdian.js",
        method:"GET",
        dataType:"json",
        data:{
            cityName:cityName
        },
        xhrFields:{
            withCredentials:true
        }
    })
    .done(function(data){
        // console.log(data);
        if(data.code=="success"){
            $(".hotel_spot").find("ul").remove();
            var str='<ul class="clearfix">';
                for(i=0;i<data.data.viewSpot.length;i++){
                    str+='<li title="'+data.data.viewSpot[i]+'">'+data.data.viewSpot[i]+'</li>';
                }
            str+='</ul>';
            $(".hotel_spot").append(str);
        }else if(data.code=="city_not_found"){
            $(".hotel_spot").find("ul").remove();
            $(".spot .notFound_position").css("display","block");
        }
    })
    $(".ErrorMsg").css("display","none");
})
$(".hotel_spot").on("click","li",function(){
    $("#search").val($(this).html());
})

// 模拟单选按钮
    // 价格
var data_i=""; //判断是否点击的是当前的价格
$(".price span").click(function(){
    var allRadio=$(".price span b");    
    if(data_i !=$(this).attr("data-price")){
        $("#search").attr("data-price",$(this).attr("data-price"));
        for(i=0;i<allRadio.length;i++){
            $(".price .unlimited").css("background","#ddd");
            allRadio.css("background","url(img/icon_checkbox.png)");
            $(this).find("b").css("background","url(img/icon_checkbox_choose.png)");
        }
        data_i=$(this).attr("data-price");
        $(".user-defined input").val("");
    }else{
        $("#search").attr("data-price","");
        $(this).find("b").css("background","url(img/icon_checkbox.png)");
        data_i="";
        $(".user-defined input").val("");
        $(".price .unlimited").css("background","#5944C3");
    }
    $(".ErrorMsg").css("display","none");
})
$(".price .unlimited").click(function(){
    data_i="";
    $("#search").attr("data-price","");
    $(this).css("background","#5944C3");
    $(this).parent().find("b").css("background","url(img/icon_checkbox.png)");
})
    // 自定义价格
$(".user-defined input").keyup(function(){
    data_i="";
    if($(".lower_limit").val().length!=0 || $(".Upper_limit").val().length!=0 ){
        $(".price span b").css("background","url(img/icon_checkbox.png)");
        $(".price .unlimited").css("background","#ddd")
    }
})
$(".user-defined input").click(function(){    
    $(this).css("border","1px solid #5944C3");
    $(".ErrorMsg").css("display","none");
})
$(".user-defined input").blur(function(){    
    $(this).css("border","1px solid #C0CCDA");
})
$(".submitPrice").click(function(){
    if( Number($(".Upper_limit").val()) <= Number($(".lower_limit").val()) ){
        $(".ErrorMsg").css("display","block");
        $(".ErrorMsg").html("请输入正确的价格区间");
        return;
    }
    if( Number($(".Upper_limit").val()) > Number($(".lower_limit").val()) ){
        var subprice=$(".lower_limit").val()+","+$(".Upper_limit").val();
        $("#search").attr("data-price",subprice);
        $(".ErrorMsg").css("display","none");
    }
})
    // 星级 
$(".star .starLevel").click(function(){
    var allRadio=$(".star .starLevel b");
    if(data_i != $(this).attr("data-star")){
        $("#search").attr("data-specialLevel","");
        $("#search").attr("data-star",$(this).attr("data-star"));

        $(".star b").css("background","url(img/icon_checkbox.png)");
        for(i=0;i<allRadio.length;i++){        
            $(".star .unlimited").css("background","#ddd");
            allRadio.css("background","url(img/icon_checkbox.png)");
            $(this).find("b").css("background","url(img/icon_checkbox_choose.png)");
        }
        data_i=$(this).attr("data-star");
    }else{
        $("#search").attr("data-star","");
        $(this).find("b").css("background","url(img/icon_checkbox.png)");
        data_i="";
        $(".star .unlimited").css("background","#5944C3");
    }
    $(".ErrorMsg").css("display","none");
})
$(".star .specialLevel").click(function(){
    var allRadio=$(".star .specialLevel b");
    if(data_i != $(this).attr("data-star")){
        $("#search").attr("data-star","");
        $("#search").attr("data-specialLevel",$(this).attr("data-star"));

        $(".star b").css("background","url(img/icon_checkbox.png)");
        for(i=0;i<allRadio.length;i++){
            $(".star .unlimited").css("background","#ddd");
            allRadio.css("background","url(img/icon_checkbox.png)");
            $(this).find("b").css("background","url(img/icon_checkbox_choose.png)");
        }
        data_i=$(this).attr("data-star");
    }else if(data_i == $(this).attr("data-star")){
        $("#search").attr("data-specialLevel","");        
        $(this).find("b").css("background","url(img/icon_checkbox.png)");
        data_i="";        
        $(".star .unlimited").css("background","#5944C3");
    }
    $(".ErrorMsg").css("display","none");
})
$(".star .unlimited").click(function(){    
    data_i="";
    $(this).css("background","#5944C3");
    $(this).parent().find("b").css("background","url(img/icon_checkbox.png)");
    $("#search").attr("data-star","");
})
    // 品牌
var brand_i=1;  //判断传参是否存在当前品牌
var brand_a=""; //判断当前酒店是否被选中

$(".brand span").click(function(){
    $(".ErrorMsg").css("display","none");
    var allRadio=$(".brand span b");
    
    if( brand_a.indexOf( $(this).attr("data-brand") ) == -1 ){
        // var src = $(this).find("b").attr("background-image");
        // src = src.split("/");
        // src1 = src[src.length-2]+ "/" +$(this).find("img").attr("data-src"); 
        // $(this).find("img").attr("data-src",src[src.length-1]);
        // $(this).find("img").attr("src",src1);
        $(".brand .unlimited").css("background","#ddd");
        $(this).find("b").css("background","url(img/icon_checkbox_choose.png)");

        var brand = [];
        if( $("#search").attr("data-brand") == undefined){
            brand = [];
        }else if( $("#search").attr("data-brand")  == "" ){
            brand = [];
        }else{
            var brand_all = $("#search").attr("data-brand");
            brand_all = brand_all.split(",");
            brand .push( brand_all );
        }
        if( brand.length == 0){
            brand.push( $(this).attr("data-brand") ) ;
        }
        if( brand.length > 0 ){
            for( i=0 ; i<brand.length;i++){
                if(  brand[i].indexOf( $(this).attr("data-brand") ) >= 0){
                    brand_i = 2;
                }
            }
        }
        if( brand_i === 1 ){
            brand.push( $(this).attr("data-brand") ) ;
        }
        brand_i = 1;
        $("#search").attr("data-brand",brand);
        brand_a += $(this).attr("data-brand");
    }else if( brand_a.indexOf( $(this).attr("data-brand") ) >= 0 ){
        // var src = $(this).find("img").attr("src");
        // src = src.split("/");
        // src1 = src[src.length-2]+ "/" +$(this).find("img").attr("data-src"); 
        // $(this).find("img").attr("data-src",src[src.length-1]);
        // $(this).find("img").attr("src",src1);
        $(this).find("b").css("background","url(img/icon_checkbox.png)");
        data_i="";
        $(".brand .unlimited").css("background","#5944C3");

        var brand_all = $("#search").attr("data-brand");
        var cancel_i = ""; //用来删除取消的酒店
        brand_all = brand_all.split(",");
        var x  =  $(this).attr( "data-brand");
        for( i=0 ; i<brand_all.length;i++){
            if( x  == brand_all[i] ){ 
                cancel_i = i;
            } 
        }
        brand_all.splice( cancel_i , 1 );
        $("#search").attr("data-brand",brand_all);
        var str = brand_a;
        var reg = new RegExp( $(this).attr("data-brand") );
        brand_a = str.replace(reg,"");
    }  
    if( brand_a != ""){
        $(".brand .unlimited").css("background","#ddd");
    } else {
        $(".brand .unlimited").css("background","#5944C3");
    }
})
$(".brand .unlimited").click(function(){
    brand_a="";
    data_i="";
    $(this).css("background","#5944C3");
    $(this).parent().find("b").css("background","url(img/icon_checkbox.png)");
    $("#search").attr("data-brand","");
})

var page=1;
// 筛选下半部分
$(".search_Btn").click(function(){
    var maxPage;
    var tag=true;
    var city_Name=$("#selectCity").val();
    // console.log(city_Name);
    if(city_Name !=""){
        $(".ErrorMsg").css("display","none");
      
        SearchCityMsg(page);
        console.log("maxPage"+maxPage);
        //分页器
        if(tag){
            $('.box').pagination({
                pageCount:maxPage,
                jump: true,
                coping: true,
                homePage: '首页',
                endPage: '末页',
                prevContent: '上页',
                nextContent: '下页',
                callback: function (api) {
                    console.log(api.getCurrent());
                    page = api.getCurrent();
                    // ajax1(page);
                }
            });
            tag=false;
        }
       
    }else if(city_Name ==""){
        $(".ErrorMsg").css("display","block");
        $(".ErrorMsg").html("请选择一个城市");
    }
})
//封装ajax请求
function SearchCityMsg(page,overallRating,price,distance){

    var city_Name=$("#selectCity").val();
    var checkTime="";//预定时间段
    var abc=$("#daterange-btn").find("span").html().split("-");
    // console.log(abc);
    var enter_hotel=abc.shift();
    // console.log(enter_hotel);入店时间
    var enter_time=Date.parse(enter_hotel);
    enter_time=enter_time/1000
    // console.log(enter_time);入店时间戳
    // var leave_hotel=abc[abc.length-1];
    var leave_hotel=abc.pop();
    // console.log(leave_hotel);离店时间
    var leave_time=Date.parse(leave_hotel);
    leave_time=leave_time/1000;
    // console.log(leave_time);离店时间戳
    checkTime=enter_time+","+leave_time;
    // console.log(checkTime);

    var searchHotel=$("#search").val();// 酒店关键字
    var position="";//位置名称

    var priceRange="";//价格区间
    if($("#selectCity").attr("data-price") !=undefined ){
        priceRange= $("#selectCity").attr("data-price");
    }
    var starLevel="";//星级
    if($("#selectCity").attr("data-star")!=undefined){
        starLevel=$("#selectCity").attr("data-star");
    }

    var specialLevel = ""; //
    if( $("#selectCity").attr("data-speciallevel") != undefined ){
        specialLevel = $("#selectCity").attr("data-speciallevel");
    }

    var brand="";//品牌
    if( $("#selectCity").attr("data-brand") != undefined ){
        brand = $("#selectCity").attr("data-brand");
    }

    if(city_Name !=""){
        $.ajax({
            url:url+"v1/hotel/list",
            // url:"php/jiudian.js",
            method:"GET",
            dataType:"json",
            data:{
                cityName:city_Name,
                limit:5,
                page,
                checkTime,
                hotelKeyword:searchHotel,
                position:position,
                priceRange:priceRange,
                starLevel:starLevel,
                speciallevel:specialLevel,
                brand:brand,
                overallRating:overallRating,
                price:price,
                distance:distance
            },
            xhrFields: {
                withCredentials: true // 允许跨域名储存和访问cookie
            }
        })
        .done(function(data){
            console.log(data);
            $(".hotel-msg li").remove();
            var hotel_data = data.data.hotelList;
            var str="";
            var map_a=[];
            var location={};
            // console.log(hotel_data[0].location.lng)
            if(data.code=="success"){
                
                // 创建地图实例
                const map = new BMap.Map("container") // 创建一个地图实例，其参数可以是元素id也可以是元素对象
                for(i=0;i<hotel_data.length;i++){
                    var hotelId=hotel_data[i]._id;//保存酒店ID
                    var star_num="";//保存星的数量
                    var star_num_str="";
                    star_num=hotel_data[i].star_level;
                    for(j=0;j<star_num;j++){
                        star_num_str+='<img src="img/icon_star.png" class="star">';
                    }
                    str+='<li class="clearfix">';
                        //酒店图片
                        str+='<img src="'+url_file+hotel_data[i].picture[1]+'" class="hotelPic lf">';
                        // str+='<img src="img/jiudian.png" class="hotelPic lf">';
                    str+='<div class="hotel_detail lf">';
                        str+='<div class="hotel_title clearfix">';
                            str+='<span class="hotelName lf">'+hotel_data[i].name+'</span>'+'<span class="allstar gt">'+star_num_str +'</span></div>';
                        str+='<div class="address">'+hotel_data[i].address+'<a>-地图</a>'+'</div></div>';
                    str+='<div class="comment lf">';
                        str+='<p><span class="score">'+ hotel_data[i].overall_rating +'</span>/5分</p>';
                        str+='<p><span class="comment_num">'+ hotel_data[i].comment_num +'</span>次点评</p></div>';
                    str+='<div class="hotel_pay gt">';
                        str+='<p><span class="hotel_price">'+"￥"+ hotel_data[i].price +'</span>起</p><a href="hoteldetail.html?hotelId='+hotelId+'">查看详情</a></div>';
                    str+='</div></li>';
                    localStorage.HotelId=hotelId;

                    // 地图酒店2个坐标点
                    location={};
                    location.name=hotel_data[i].name;
                    location.location=new BMap.Point( hotel_data[i].location.lng , hotel_data[i].location.lat );
                    // 将每个酒店的2个坐标点push到一个空数组中
                    map_a.push(location);
                    
                }
                $(".hotel-msg").append(str);

                map.centerAndZoom(new BMap.Point(hotel_data[0].location.lng, hotel_data[0].location.lat ), 13) // 初始化地图，设置中心点坐标和地图级别
                map.enableScrollWheelZoom(true) // 启用滚轮放大缩小，默认禁用
                map.addControl(new BMap.ScaleControl()) // 添加控件，比例尺控件
                map.addControl(new BMap.NavigationControl({
                type: BMAP_NAVIGATION_CONTROL_ZOOM
                })) // 添加控件，平移缩放控件，type值表示只显示控件的缩放部分功能
                
                map_a.forEach(el => {
                const marker = new BMap.Marker(el.location) // 创建标注点
                map.addOverlay(marker) // 向地图添加标注点
                marker.setLabel(new BMap.Label(el.name, {
                    offset: new BMap.Size(20)
                })) // 向标注点添加标注文本
                })
                console.log("data.count" ,data.data.count);
                maxPage=Math.ceil(data.data.count/5);
            }
        })
    }else if(city_Name==""){
        $(".ErrorMsg").css("display","block");
        $(".ErrorMsg").html("请选择一个城市");
    }
}

    //评分 价格 距离筛选
var HotelSwitch= 1;
var overallR="";
$(".choseCity").click(function(){
    $(".ErrorMsg").hide();
})
// 评价
$(".overallRating").click(function(){ 
    $(this).css({"background":"#5944C3","color":"#fff"});
    $(this).find("i").css("background","url(img/icon_arrow_down1_white.png)");
    $(this).siblings().css({"background":"#F1F1F1","color":"#3E3E3E"});
    $(this).siblings().find("i").css("background","url(img/icon_arrow_down1.png)");
    if(HotelSwitch==1){
        $(this).find("i").css("background","url(img/icon_arrow_down1_white.png)");
        overallR=1;
        var price="";
        var distance="";
        SearchCityMsg(1,overallR,price,distance);
        HotelSwitch=2;
        // return;
    }else if(HotelSwitch==2){
        console.log(2);
        $(this).find("i").css("background","url(img/icon_arrow_up1_white.png)");
        overallR=-1;
        SearchCityMsg(1,overallR,price,distance);
        HotelSwitch=1;
    }
})
$(".priceRank").click(function(){    
    $(this).css({"background":"#5944C3","color":"#fff"});
    $(this).find("i").css("background","url(img/icon_arrow_down1_white.png)");
    $(this).siblings().css({"background":"#F1F1F1","color":"#3E3E3E"});
    $(this).siblings().find("i").css("background","url(img/icon_arrow_down1.png)");
    if(HotelSwitch==1){
        $(this).find("i").css("background","url(img/icon_arrow_down1_white.png)");
        var overallR="";
        var distance="";
        price=1;
        SearchCityMsg(1,overallR,price,distance);
        console.log(1);
        HotelSwitch=2;
        // return;
    }else if(HotelSwitch==2){
        console.log(2);
        $(this).find("i").css("background","url(img/icon_arrow_up1_white.png)");
        price=-1;
        SearchCityMsg(1,overallR,price,distance);
        HotelSwitch=1;
    }
})
$(".distance").click(function(){    
    $(this).css({"background":"#5944C3","color":"#fff"});
    $(this).siblings().css({"background":"#F1F1F1","color":"#3E3E3E"});
    $(this).siblings().find("i").css("background","url(img/icon_arrow_down1.png)");
    $(this).find("i").css("background","url(img/icon_arrow_up1_white.png)");
    var overallR="";
    var distance=1;
    var price="";
    SearchCityMsg(1,overallR,price,distance);
    console.log(1);
        // return;
})

$(document).ready(function(){
    var content_url = window.location.href;
    content_url = content_url.split("?");
    var count= content_url[ content_url.length-1 ].split("=")[ content_url[ content_url.length-1 ].split("=").length-1 ];
    var page=Math.ceil(count/5);
    ajaxhomepage();
})
// 
$(".screen-title b").click(function(){
    ajaxhomepage();
    $(this).css({"background":"#5944C3","color":"#fff"});
    $(this).parent().find("span").css({"background":"#F1F1F1","color":"rgb(62, 62, 62)"});
    $(this).parent().find("i").css("background","url('img/icon_arrow_down1.png')");
})
// 封装不传参的ajax（页面加载时，和点击推荐时）
function ajaxhomepage(){
    var city_Name=$("#selectCity").val();
    var content_url = window.location.href;
    content_url = content_url.split("?");
    var count= content_url[ content_url.length-1 ].split("=")[ content_url[ content_url.length-1 ].split("=").length-1 ];
    console.log(count);
    var city_Name2=content_url[ content_url.length-2 ].split("=")[ content_url[ content_url.length-2 ].split("=").length-1 ];
    city_Name2 = decodeURI( city_Name2 );
    $("#selectCity").val(city_Name2);
    var maxPage=Math.ceil(count/5);
    console.log(maxPage);
    var overallRating="";
    var price="";
    var distance="";
    // SearchCityMsg(page,overallRating,price,distance);
    $.ajax({
        url:url+"v1/hotel/list",
        dataType:"json",
        method:"GET",
        data:{
            cityName:city_Name2,
            limit:5,
            page:1
        },
        xhrFields: {
            withCredentials: true // 允许跨域名储存和访问cookie
        }
    }).done(function(data){
        $(".hotel-msg li").remove();
        var hotel_data = data.data.hotelList;
        var str="";        
        var map_a=[]
        ;var location={};
        // console.log(hotel_data[0].location.lng)
        if(data.code=="success"){
            const map = new BMap.Map("container") // 创建一个地图实例，其参数可以是元素id也可以是元素对象
            for(i=0;i<hotel_data.length;i++){
                var hotelId=hotel_data[i]._id;//保存酒店ID
                var star_num="";//保存星的数量
                var star_num_str="";
                star_num=hotel_data[i].star_level;
                for(j=0;j<star_num;j++){
                    star_num_str+='<img src="img/icon_star.png" class="star">';
                }
                // <img src="img/1.jpg" class="hotelPic lf">
                str=`
                    <li class="clearfix">                        
                        <img src="`+url_file+hotel_data[i].picture[2]+`" class="hotelPic lf">
                        <div class="hotel_detail lf">
                            <div class="hotel_title clearfix">
                                <span class="hotelName lf">
                                    `+hotel_data[i].name+`
                                </span>
                                <span class="allstar gt">
                                    `+star_num_str +`
                                </span>
                            </div>
                            <div class="address">
                                `+hotel_data[i].address+`
                                <a>-地图</a>
                            </div>
                        </div>
                        <div class="comment lf">
                            <p>
                                <span class="score">`+ hotel_data[i].overall_rating +`</span>/5分
                            </p>
                            <p>
                                <span class="comment_num">`+ hotel_data[i].comment_num +`</span>次点评
                            </p>
                        </div>
                        <div class="hotel_pay gt">
                            <p>
                                <span class="hotel_price">`+"￥"+ hotel_data[i].price +`</span>起
                            </p>
                            <a href="hoteldetail.html?hotelId=`+hotelId+`">查看详情</a>
                        </div>
                    </li>
                    `;
                $(".hotel-msg").append(str);

                // 地图酒店2个坐标点
                location={};
                location.name=hotel_data[i].name;
                location.location=new BMap.Point( hotel_data[i].location.lng , hotel_data[i].location.lat );
                // 将每个酒店的2个坐标点push到一个空数组中
                map_a.push(location);                
                   
            }
            map.centerAndZoom(new BMap.Point(hotel_data[0].location.lng, hotel_data[0].location.lat ), 13) // 初始化地图，设置中心点坐标和地图级别
            map.enableScrollWheelZoom(true) // 启用滚轮放大缩小，默认禁用
            map.addControl(new BMap.ScaleControl()) // 添加控件，比例尺控件
            map.addControl(new BMap.NavigationControl({
            type: BMAP_NAVIGATION_CONTROL_ZOOM
            })) // 添加控件，平移缩放控件，type值表示只显示控件的缩放部分功能
            
            map_a.forEach(el => {
            const marker = new BMap.Marker(el.location) // 创建标注点
            map.addOverlay(marker) // 向地图添加标注点
            marker.setLabel(new BMap.Label(el.name, {
                offset: new BMap.Size(20)
            })) // 向标注点添加标注文本
            }) 
        }else{
            $(".screen-main").children().remove();
            $(".screen-main").html("暂时无法获取城市列表，请重新选择城市再试");
        }
    })
    $('.box').pagination({
        pageCount:maxPage,
        jump: true,
        coping: true,
        homePage: '首页',
        endPage: '末页',
        prevContent: '上页',
        nextContent: '下页',
        callback: function (api) {
            console.log(api.getCurrent());
            
            page = api.getCurrent();
            // ajax1(page);
        }
    });
}